package by.grsu.coctails.db.tables;

import android.content.ContentValues;
import android.database.Cursor;
import by.grsu.coctails.model.db.IngredientDb;

public class IngredientsTable {

	public static final String NAME = "Ingredients";

	private static final String[] INGREDIENT_CATEGORY_COLUMNS = { "ID", "Name",
			"Image", "IngredientCategoryID", "isHaved" };

	public static final Integer ID_COLUMN_INDEX = 0;

	public static final Integer NAME_COLUMN_INDEX = 1;

	public static final String NAME_COLUMN = INGREDIENT_CATEGORY_COLUMNS[NAME_COLUMN_INDEX];

	public static final Integer IMAGE_COLUMN_INDEX = 2;

	public static final String IMAGE_COLUMN = INGREDIENT_CATEGORY_COLUMNS[IMAGE_COLUMN_INDEX];

	public static final Integer INGREDIENT_CATEGORY_ID_COLUMN_INDEX = 3;

	public static final String INGREDIENT_CATEGORY_ID_COLUMN = INGREDIENT_CATEGORY_COLUMNS[INGREDIENT_CATEGORY_ID_COLUMN_INDEX];

	public static final Integer IS_HAVED_COLUMN_INDEX = 4;

	public static final String IS_HAVED_COLUMN = INGREDIENT_CATEGORY_COLUMNS[IS_HAVED_COLUMN_INDEX];

	public static ContentValues getContentValues(IngredientDb ingredient) {
		ContentValues contentValues = new ContentValues();
		contentValues.put(IngredientsTable.NAME_COLUMN, ingredient.getName());
		if (ingredient.getImage() != null) {
			contentValues.put(IngredientsTable.IMAGE_COLUMN,
					ingredient.getImage());
		}
		contentValues.put(IngredientsTable.INGREDIENT_CATEGORY_ID_COLUMN,
				ingredient.getIngredientCategoryID());
		return contentValues;
	}

	public static IngredientDb getIngredient(Cursor cursor) {
		String name = cursor.getString(IngredientsTable.NAME_COLUMN_INDEX);
		String image = cursor.getString(IngredientsTable.IMAGE_COLUMN_INDEX);
		long categoryID = cursor
				.getInt(IngredientsTable.INGREDIENT_CATEGORY_ID_COLUMN_INDEX);
		long id = cursor.getInt(IngredientsTable.ID_COLUMN_INDEX);
		return new IngredientDb(name, image, categoryID, id);
	}
}
